package com.dba.example.guice.beans;

import java.util.List;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Page<T> {

	public static <T> Page<T> fromList(List<T> data, int offset, int size) {
		
		if (offset >= data.size()) {
			offset = 0;
		}
		if (offset + size > data.size()) {
			size = data.size() - offset;
		}
		
		return new Page<T>(data.size(), offset, data.subList(offset, offset + size));
	}
	
	private int totalRows;
	
	private int dataOffset;

	private List<T> data;
	
	public Page(int totalRows, int dataOffset, List<T> data) {
		this.totalRows = totalRows;
		this.dataOffset = dataOffset;
		this.data = data;
	}

	public List<T> getData() {
		return data;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public int getDataOffset() {
		return dataOffset;
	}

}
